home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / ODF Release 3 / Developer University / DU Projects / Talker Part / Sources / Frame.cpp < prev    next >
Encoding:
Text File  |  1996-12-11  |  5.8 KB  |  216 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 3 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //=======================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef CONTENT_H
  10. #include "Content.h"
  11. #endif
  12.  
  13. #ifndef FRAME_H
  14. #include "Frame.h"
  15. #endif
  16.  
  17. #ifndef COMMANDS_H
  18. #include "Commands.h"
  19. #endif
  20.  
  21. #ifndef DEFINES_K
  22. #include "Defines.k"            // command numbers
  23. #endif
  24.  
  25. // ----- Framework Layer -----
  26. #ifndef FWCONTXT_H
  27. #include "FWContxt.h"            // FW_CViewContext
  28. #endif
  29.  
  30. #ifndef FWCLPCMD_H
  31. #include "FWClpCmd.h"            // FW_CClipboardCommand
  32. #endif
  33.  
  34. // ----- OS Layer -----
  35. #ifndef FWCFMRES_H
  36. #include "FWCFMRes.h"            // FW_PSharedLibraryResourceFile
  37. #endif
  38.  
  39. #ifndef FWMENU_H
  40. #include "FWMenu.h"                // FW_CMenuBar, etc.
  41. #endif
  42.  
  43. #ifndef FWEVENT_H
  44. #include "FWEvent.h"            // FW_CMenuEvent, FW_CMouseEvent
  45. #endif
  46.  
  47. #ifndef FWRECSHP_H
  48. #include "FWRecShp.h"            // FW_CRectShape
  49. #endif
  50.  
  51. #ifndef FWPICSHP_H
  52. #include "FWPicShp.h"            // FW_CPicture, FW_CPictureShape
  53. #endif
  54.  
  55. #ifndef FWRRCSHP_H
  56. #include "FWRRcShp.h"            // FW_CRoundRectShape
  57. #endif
  58.  
  59. #ifndef FWDRCMD_H
  60. #include "FWDrCmd.h"            // FW_CDropCommand
  61. #endif
  62.  
  63. // ----- OpenDoc Includes -----
  64. #ifndef SOM_ODDragItemIterator_xh
  65. #include <DgItmIt.xh>            // ODDragItemIterator
  66. #endif
  67.  
  68. #ifndef SOM_ODTranslation_xh    
  69. #include <Translt.xh>            // ODTranslation    
  70. #endif
  71.  
  72. #ifndef SOM_Module_OpenDoc_StdProps_defined
  73. #include <StdProps.xh>            // kODPropContents
  74. #endif
  75.  
  76. //========================================================================================
  77. #ifdef FW_BUILD_MAC
  78. #pragma segment Talker
  79. #endif
  80.  
  81. FW_DEFINE_AUTO(CTalkerFrame)
  82.  
  83. //========================================================================================
  84. CTalkerFrame::CTalkerFrame(Environment* ev, ODFrame* odFrame, 
  85.                             FW_CPresentation* presentation, CTalkerContent* content)
  86.   : FW_CFrame(ev, odFrame, presentation, content->GetPart(ev)),
  87.     FW_MDroppableFrame(ev, this),    
  88.     fTalkerContent(content),
  89.     fPictShape(NULL)
  90. {
  91.     this->MyInitPicture(ev);
  92.     FW_END_CONSTRUCTOR
  93. }
  94.  
  95. //----------------------------------------------------------------------------------------
  96. void
  97. CTalkerFrame::MyInitPicture(Environment* ev)
  98. {
  99.     FW_CPicture picture = fTalkerContent->MyGetPicture(ev);
  100.     fFrameRect = this->GetBounds(ev);        // Get new Frame Rect
  101.     fPictShape = FW_NEW(FW_CPictureShape, (picture, fFrameRect));
  102. }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. CTalkerFrame::~CTalkerFrame()
  106. {
  107.     FW_START_DESTRUCTOR
  108.     delete fPictShape;
  109. }
  110.  
  111. //----------------------------------------------------------------------------------------
  112. void 
  113. CTalkerFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  114. {
  115.     FW_CViewContext context(ev, this, odFacet, invalidShape);
  116.     
  117.     // erase invalid shape
  118.     FW_CRect invalidRect;
  119.     context.GetClipRect(invalidRect);
  120.     FW_CRectShape::RenderRect(context, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  121.     // draw the picture
  122.     fPictShape->SetPicture( fTalkerContent->MyGetPicture(ev) );
  123.     fPictShape->Render(context);
  124.     // draw a frame around it
  125.     FW_CRoundRectShape::RenderRoundRect(context,
  126.                                         fFrameRect, 
  127.                                         FW_CPoint(FW_IntToFixed(30), FW_IntToFixed(30)),
  128.                                         FW_kFrame,
  129.                                         FW_CInk(FW_kRGBBlue));
  130. }
  131.  
  132. //----------------------------------------------------------------------------------------
  133. void 
  134. CTalkerFrame::FrameShapeChanged(Environment* ev)
  135. {
  136.     FW_CFrame::FrameShapeChanged(ev);
  137.     fFrameRect = this->GetBounds(ev);    // Get new frame rect
  138.     // modify picture
  139.     FW_CPicture picture = fPictShape->GetPicture();
  140.     fPictShape->SetGeometry(picture, fFrameRect);
  141.     // force redraw of whole frame
  142.     this->Invalidate(ev, fFrameRect);            
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. FW_Handled 
  147. CTalkerFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus,
  148.                             FW_Boolean isRoot)    // Override
  149. {
  150.     FW_UNUSED(isRoot);
  151.     if (hasMenuFocus) {
  152.         FW_Boolean hasRightProperty = false;
  153.         menuBar->EnableCommand(ev, kODCommandPaste, HasSupportedKindOnClipboard(ev));
  154.         menuBar->EnableCommand(ev, cFasterCmd, TRUE);
  155.         menuBar->EnableCommand(ev, cSlowerCmd, TRUE);
  156.     }
  157.     return FW_kNotHandled;
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. FW_Handled 
  162. CTalkerFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  163. {
  164.     FW_Handled menuHandled = FW_kHandled;
  165.     CTalkerCommand* cmd = NULL;
  166.     switch (theMenuEvent.GetCommandID(ev)) { 
  167.         case cFasterCmd:         
  168.             cmd = FW_NEW(CTalkerCommand, (ev, cFasterCmd, this, 
  169.                                             fTalkerContent->MyGetTalker()));
  170.             cmd->Execute(ev);
  171.             break;
  172.         
  173.         case cSlowerCmd: 
  174.             cmd = FW_NEW(CTalkerCommand, (ev, cSlowerCmd, this, 
  175.                                             fTalkerContent->MyGetTalker()));
  176.             cmd->Execute(ev);
  177.             break;
  178.  
  179.         default:
  180.             menuHandled = FW_kNotHandled;
  181.     }
  182.     return menuHandled;
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. FW_Handled 
  187. CTalkerFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  188. {    
  189.     FW_Handled handledEvent = FW_kNotHandled;
  190.     if (theMouseEvent.GetNumberOfClicks(ev) == 2) {
  191.         fTalkerContent->MySayText(ev);
  192.         handledEvent = FW_kHandled;
  193.         }
  194.     return handledEvent;
  195. }
  196.  
  197. //----------------------------------------------------------------------------------------
  198. FW_CDropCommand* 
  199. CTalkerFrame::NewDropCommand(Environment *ev, 
  200.                                     FW_CFrame* frame,
  201.                                     ODDragItemIterator* dropInfo, 
  202.                                     ODFacet* facet, 
  203.                                     const FW_CPoint& dropPoint)
  204. {
  205.     return FW_NEW(FW_CDropCommand, (ev, frame, dropInfo, facet, dropPoint, !FW_kCanUndo) );
  206. }
  207.  
  208. //----------------------------------------------------------------------------------------
  209. FW_CClipboardCommand* 
  210. CTalkerFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  211. {
  212.     return FW_NEW(FW_CClipboardCommand, 
  213.             (ev, commandID, this, ! FW_kCanUndo) );
  214. }
  215.  
  216.